package com.fgxia.user.controller;

import com.fgxia.user.service.ISiteInfoService;
import com.ruoyi.business.domain.SiteInfo;
import com.ruoyi.business.domain.bo.SiteInfoBo;
import com.ruoyi.business.domain.vo.SiteInfoVo;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 地址信息
 *
 * @author yyt
 * @date 2024-04-20
 **/
@RestController
@RequiredArgsConstructor
@RequestMapping("/user/site")
public class SiteInfoController extends BaseController {

    private final ISiteInfoService siteInfoService;

    @GetMapping("/list")
    public TableDataInfo<SiteInfoVo> list(SiteInfo siteInfo, PageQuery pageQuery) {
        siteInfo.setRelevanceUserId(getUserId());
        return siteInfoService.selectVoList(siteInfo, pageQuery);
    }

    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@RequestBody SiteInfoBo siteInfoBo) {
        siteInfoBo.setRelevanceUserId(getUserId());
        Boolean result = siteInfoService.insertByBo(siteInfoBo);
        return toAjax(result);
    }

    @PutMapping()
    public R<Void> update(@RequestBody SiteInfoBo siteInfoBo) {
        Boolean result = siteInfoService.updateByBo(siteInfoBo);
        return toAjax(result);
    }

    @DeleteMapping("/{siteId}")
    public R<Void> delete(@PathVariable Long siteId) {
        Boolean result = siteInfoService.deleteById(siteId);
        return toAjax(result);
    }

}
